package com.yanqu.road.server.pb;

import com.yanqu.road.entity.cricket.CricketData;
import com.yanqu.road.entity.cricket.CricketProperty;
import com.yanqu.road.entity.cricket.CricketSkill;
import com.yanqu.road.entity.cricket.CricketTalent;
import com.yanqu.road.entity.cricket.court.CricketCourtDefenseData;
import com.yanqu.road.entity.cricket.court.CricketCourtUserData;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.manager.user.CrossUserMgr;

public class CrossCricketPb {

    /**
     * 蛐蛐资质(天生属性)
     */
    public static CricketProto.CricketTalentTempMsg.Builder parseCricketTalentTemp(CricketTalent cricketTalent) {
        if (cricketTalent == null) {
            return null;
        }
        CricketProto.CricketTalentTempMsg.Builder builder = CricketProto.CricketTalentTempMsg.newBuilder();
        builder.setAtk(cricketTalent.getAtk());
        builder.setHp(cricketTalent.getHp());
        builder.setPower(cricketTalent.getPower());
        return builder;
    }

    /**
     * 蛐蛐属性(战斗属性)
     */
    public static CricketProto.CricketPropertyTempMsg.Builder parseCricketPropertyTemp(CricketProperty cricketProperty) {
        if (cricketProperty == null) {
            return null;
        }
        CricketProto.CricketPropertyTempMsg.Builder builder = CricketProto.CricketPropertyTempMsg.newBuilder();
        builder.setAtk(cricketProperty.getAtk());
        builder.setHp(cricketProperty.getHp());
        builder.setPower(cricketProperty.getPower());
        builder.setAbility(cricketProperty.getAbility());
        return builder;
    }

    /**
     * 蛐蛐技能
     */
    public static CricketProto.CricketSkillTempMsg.Builder parseCricketSkillTemp(CricketSkill cricketSkill) {
        if (cricketSkill == null) {
            return null;
        }
        CricketProto.CricketSkillTempMsg.Builder builder = CricketProto.CricketSkillTempMsg.newBuilder();
        builder.setSkillId(cricketSkill.getSkillId());
        return builder;
    }

    public static CricketProto.CricketUserBattleDataTemp.Builder parseCricketUserBattleDataTemp(CricketCourtUserData userData) {
        if (userData == null) {
            return null;
        }
        CricketProto.CricketUserBattleDataTemp.Builder builder = CricketProto.CricketUserBattleDataTemp.newBuilder();
        builder.setUserId(userData.getUserId());
        UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(userData.getUserId());
        if(userBaseInfo != null){
            builder.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
        }
        builder.setScore(userData.getScore());
        builder.setCourtBadgeId(userData.getCourtBadgeId());
        return builder;
    }

    /**
     * 获取蛐蛐匹配战斗数据
     */
    public static CricketProto.CricketMatchDataTemp.Builder parseCricketMatchDataTemp(CricketCourtDefenseData defenseData) {
        if (defenseData == null) {
            return null;
        }
        CricketProto.CricketMatchDataTemp.Builder builder = CricketProto.CricketMatchDataTemp.newBuilder();
        builder.setUserId(defenseData.getUserId());
        builder.setCricketId(defenseData.getCricketId());
        builder.setQuality(defenseData.getQuality());
        builder.setTitle(defenseData.getTitle());
        builder.setLittleTitle(defenseData.getLittleTitle());
        builder.setTalent(parseCricketTalentTemp(defenseData.getTalent()));
        builder.setProperty(parseCricketPropertyTemp(defenseData.getProperty()));
        for (CricketSkill cricketSkill : defenseData.getBattleSkill()) {
            builder.addBattleSkill(parseCricketSkillTemp(cricketSkill));
        }
        for (CricketSkill cricketSkill : defenseData.getAttackSkill()) {
            builder.addAttackSkill(parseCricketSkillTemp(cricketSkill));
        }
        for (CricketSkill cricketSkill : defenseData.getInitSkill()) {
            builder.addInitSkill(parseCricketSkillTemp(cricketSkill));
        }
        for (CricketSkill cricketSkill : defenseData.getSkill()) {
            builder.addSkill(parseCricketSkillTemp(cricketSkill));
        }
        return builder;
    }

    public static CricketTalent parseCricketTalent(CricketProto.CricketTalentTempMsg temp) {
        CricketTalent talent = new CricketTalent();
        talent.setAtk(temp.getAtk());
        talent.setHp(temp.getHp());
        talent.setPower(temp.getPower());
        return talent;
    }

    public static CricketProperty parseCricketProperty(CricketProto.CricketPropertyTempMsg temp) {
        CricketProperty property = new CricketProperty();
        property.setAtk(temp.getAtk());
        property.setHp(temp.getHp());
        property.setPower(temp.getPower());
        property.setAbility(temp.getAbility());
        return property;
    }

    public static CricketSkill parseCricketSkill(CricketProto.CricketSkillTempMsg temp) {
        CricketSkill skill = new CricketSkill();
        skill.setSkillId(temp.getSkillId());
        return skill;
    }

    public static CricketCourtDefenseData parseCricketCourtDefenseData(CricketProto.CricketMatchDataTemp temp) {
        CricketCourtDefenseData defenseData = new CricketCourtDefenseData();
        defenseData.setUserId(temp.getUserId());
        defenseData.setCricketId(temp.getCricketId());
        defenseData.setQuality(temp.getQuality());
        defenseData.setTitle(temp.getTitle());
        defenseData.setLittleTitle(temp.getLittleTitle());
        defenseData.setTalent(parseCricketTalent(temp.getTalent()));
        defenseData.setProperty(parseCricketProperty(temp.getProperty()));
        for (CricketProto.CricketSkillTempMsg cricketSkillTempMsg : temp.getBattleSkillList()) {
            defenseData.getBattleSkill().add(parseCricketSkill(cricketSkillTempMsg));
        }
        for (CricketProto.CricketSkillTempMsg cricketSkillTempMsg : temp.getAttackSkillList()) {
            defenseData.getAttackSkill().add(parseCricketSkill(cricketSkillTempMsg));
        }
        for (CricketProto.CricketSkillTempMsg cricketSkillTempMsg : temp.getInitSkillList()) {
            defenseData.getInitSkill().add(parseCricketSkill(cricketSkillTempMsg));
        }
        for (CricketProto.CricketSkillTempMsg cricketSkillTempMsg : temp.getSkillList()) {
            defenseData.getSkill().add(parseCricketSkill(cricketSkillTempMsg));
        }
        return defenseData;
    }
}
